Example 0.7 shows how to import and draw an image from a file. This program works with the GraphicsImporterDrawer object to import and display a variety of image file formats. The media required for this sample code is any image file that can be imported using the GraphicsImporterDrawer .
The quicktime.app.image package has two primary image display classes: GraphicsImporterDrawer and ImagePresenter . These classes implement both ImageSpec and QTDrawable interfaces. GraphicsImporterDrawer uses GraphicsImporter to read, decompress, and display image files.
import quicktime.*;
import quicktime.std.StdQTConstants;
import quicktime.std.image.GraphicsImporter;
import quicktime.io.QTFile;
import quicktime.app.display.QTCanvas;
import quicktime.app.image.*;
public class ImageFileDemo extends Frame implements StdQTConstants {
public static void main (String args[]) {
try {
QTSession.open();
int[] fileTypes = { kQTFileTypeGIF, kQTFileTypeJPEG, kQTFileTypePicture };
QTFile qtf = QTFile.standardGetFilePreview (fileTypes);
ImageFileDemo ifd = new ImageFileDemo (qtf);
ifd.pack();
ifd.show();
ifd.toFront();
} catch (QTException e) {
if (e.errorCode() != Errors.userCanceledErr)
e.printStackTrace();
QTSession.close();
}
}
ImageFileDemo (QTFile qtf) throws QTException {
super (qtf.getName());
QTCanvas canv = new QTCanvas();
add (canv, "Center");
GraphicsImporterDrawer myImageFile = new GraphicsImporterDrawer (qtf);
canv.setClient (myImageFile, true);
addWindowListener(new WindowAdapter () {
public void windowClosing (WindowEvent e) {
QTSession.close();
dispose();
}
public void windowClosed (WindowEvent e) {
System.exit(0);
}
});
}
}
| Previous | Chapter Top | Next |